package se.webbzon.boltzmann.minigame.animation;

import se.webbzon.boltzmann.minigame.sandbox.AnimationListener;
import se.webbzon.boltzmann.minigame.sandbox.DefaultSandBoxAnimation;
import se.webbzon.boltzmann.minigame.sandbox.SandBoxAnimatable;
import se.webbzon.boltzmann.minigame.sandbox.SandBoxAnimation;

public class OrAnimation extends DefaultSandBoxAnimation {
	
	// The animations of this animation collection
	private final SandBoxAnimation[] animations;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public OrAnimation(SandBoxAnimation...animations) {
		AnimationListenerImpl listener = new AnimationListenerImpl();
		this.animations = animations;
		for (SandBoxAnimation animation : animations)
			animation.addListener(listener);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onStepEnd(SandBoxAnimatable picture) {
		for (SandBoxAnimation animation : animations)
			animation.onStepEnd(picture);
	}
	
	/*============================================================
	Private Classes
	============================================================*/
	
	private final class AnimationListenerImpl implements AnimationListener {

		@Override public void onComplete(SandBoxAnimation animation) {
			for (SandBoxAnimation a : animations)
				a.removeListener(this);
			notifyComplete();
		}
		
	}

}
